import CONSTANT from '@/common/constants.js';
import http from '@/common/http.js';
import Picker from 'vux/src/components/picker/index.vue'
import Popup from 'vux/src/components/popup/index.vue'
import TransferDom from 'vux/src/directives/transfer-dom/index'

export default {
  name: 'oneToOneMore',
  components: {Picker, Popup},
  directives: {
    TransferDom
  },
  data () {
    return {
      showdy: false,
      showxb: false,
      shownl: false,
      showSketch: false,
      eventAll: {},
      area: [],
      aready: [],
      sexs: ['不限', '男', '女'],
      sex: [],
      ages: ['不限', '12', '13', '14'],
      age: [],
      biunique_id: '',
      title: '',
      peopleNum: '',
      pageNo: 1,
      pageSize: 20,
      studentList: []
    }
  },
  mounted () {
    this.biunique_id = this.$route.query.event_id
    if (this.biunique_id ==  '82c4d2202b8948cfa42b292b4795b74f') {
        this.showSketch = true
    }
    this.$emit('ifOpenid', this.$route.path,this.biunique_id)
    http.post(CONSTANT.BIUNIQUE_VIEW, {biunique_id: this.biunique_id}, (res) => {
      if (res.code == 200) {
        this.eventAll = res.obj
        this.$emit('ShareAppMessage', this.eventAll.theme, '【亲青筹】' + this.eventAll.sketch, 'http://www.qqchou.org/a/wxinterface/wxOAuth?category=7&event_id=' + this.biunique_id, this.imageUrl.imageUrl + this.eventAll.picture)
      }
    })
    http.post(CONSTANT.SCREEN, {biunique_id: this.biunique_id}, (res) => {
      console.log(res)
      if (res.code == 200) {
        this.title = res.obj.title
        this.peopleNum = res.obj.needNumber
        this.pageSize = this.peopleNum
        this.goScreen()
      }
    })
  },
  methods: {
    gooneToOneScreen () {
      this.$router.push({path: '/oneToOneScreen',query:{event_id: this.biunique_id}})
    },
    goScreen () {
      var city = ''
      var country = ''
      var sexS = ''
      var ageS = ''
      http.post(CONSTANT.SEARCH_STUDENT, {
        pageNo: this.pageNo,
        pageSize: this.pageSize,
        age: ageS,
        city: city,
        country: country,
        sex: sexS,
        biunique_id: this.biunique_id
      }, (res) => {
        console.log(res)
        if (res.code == 200) {
          if (res.errmsg == '没有更多的学生') {
            this.studentList = []
            return
          }
          this.studentList = res.list
          for (var stu = 0; stu < this.studentList.length; stu++) {
            var names = this.studentList[stu].name
            if(this.biunique_id != 'eb783144cf9e47f999708a67d48b576d') {
              names = names.split('')  // 将a字符串转换成数组
              names.splice(1, 1, '*') // 将1这个位置的字符，替换成'xxxxx'. 用的是原生js的splice方法。
              names = names.join('')  // 将数组转换成字符串。  完成。
            }
            this.studentList[stu].name = names
            if (this.studentList[stu].sex == 'woman') {
              this.studentList[stu].sex = '女'
            } else if (this.studentList[stu].sex == 'man') {
              this.studentList[stu].sex = '男'
            } else {
              this.studentList[stu].sex = ''
            }
          }
        }
      })
    },
    goOneToOneDonation (id) {
      this.$router.push({path: '/oneToOneDonation', query: {id: id,event_id:this.biunique_id}})
    },
    comeBack () {
      window.history.go(-1)
    }
  }
}
